09. Exercise: Override onDraw()
22 08 AAK OnDraw SC V2
Android Developer Documentation
Exercise
In this exercise you are going to override onDraw().
- Override
onDraw()and draw the contents of the cachedextraBitmapon the canvas associated with the view. ThedrawBitmap()Canvasmethod comes in several versions. In this code, you provide the bitmap, the x and y coordinates (in pixels) of the top left corner, andnullfor thePaint, as you'll set that later.
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawBitmap(extraBitmap, 0f, 0f, null)
}
Note: The 2D coordinate system used for drawing on a Canvas is in pixels, and the origin (0,0) is at the top left corner of the Canvas.